import { AccountSchema } from './schema/AccountSchema';
import { MahjongSchema } from './schema/MahjongSchema';

//对象池,存放从数据库中读取出来的用户数据
//收到用户下线的通知，才会把这个用户的数据清空
export class ObjectPool
{
    private _pool:Object;
    private static _instance:ObjectPool;

    constructor()
    {
        this._pool = new Object();
    }

    public static getInstance():ObjectPool
    {
        if(this._instance == null)
        {
            this._instance = new ObjectPool();
        }
        return this._instance;
    }

    /**在创建的需要确保acc的唯一性 */
    public addObj(obj:BaseObject,acc:string):void
    {
        this._pool[acc] = obj;
    }

    public deleteObj(acc:string):void
    {
        delete this._pool[acc];
    }

    /**有可能是空 */
    public getObj(acc:string):BaseObject
    {
        return this._pool[acc];
    }

    /**是否包含 */
    public contains(acc:string):boolean
    {
        return this._pool[acc]?true:false;
    }
}


export class BaseObject
{
    /**account里的_id，其他数据库里的_id都以这个_id为准 */
    public _id:Object;
    public acc:AccountSchema;
    public mahjong:MahjongSchema;
}